home *** CD-ROM | disk | FTP | other *** search
/ CD Concept 6 / CD Concept 06.iso / mac / UTILITAIRE / Little Smalltalk v3.1.4 / C Source / Sources / initial.c < prev    next >
Text File  |  1995-01-24  |  4KB  |  150 lines

  1. /*
  2.     Little Smalltalk, version 3
  3.     Written by Tim Budd, June 1988
  4.  
  5.     initial image maker
  6. */
  7. # include <stdio.h>
  8. # include <stdlib.h>
  9. # include "env.h"
  10. # include "memory.h"
  11. # include "names.h"
  12.  
  13. int initial = 1;    /* making initial image */
  14.  
  15. /* lightspeed C not using argc/argv features */
  16. # ifdef NOARGC
  17. char *argv[] = {"initial", "basic.st","mag.st","collect.st", "file.st",
  18.         "mult.st", 
  19. #   ifdef STDWIN
  20.         "graphics.st",
  21. #     ifdef TCL
  22.         "tclwin.st", "browser.st", "macfile.st", "inspector.st", "notifier.st", 0};
  23. int argc = 12;
  24. #     else 
  25.         "stdwin.st", 0};
  26. int argc = 8;
  27. #     endif
  28. #   endif
  29. #   ifndef STDWIN
  30.         "tty.st", 0};
  31. int argc = 7;
  32. #   endif
  33.  
  34.  
  35. #   ifdef THINKC
  36. # include "initial.proto.h"
  37. # include "parser.proto.h"
  38. # include "news.proto.h"
  39. # include "names.proto.h"
  40. # include "interp.proto.h"
  41. # include "memory.proto.h"
  42. #   else
  43. static goDoIt(char *text);
  44. static makeInitialImage(void);
  45.  
  46. static goDoIt(char *);
  47. static makeInitialImage(void);
  48. static goDoIt(char *);
  49. static makeInitialImage(void);
  50. #   endif
  51.  
  52. main (void)
  53. # endif
  54. {     
  55.     char    methbuf [150];        /* Changed from 100, JRB 5/94 */
  56.     int        i;
  57.  
  58.     initMemoryManager();
  59.  
  60.     makeInitialImage();
  61.  
  62.     initCommonSymbols();
  63.  
  64.     for (i = 1; i < argc; i++) {
  65.         fprintf(stderr,"%s:\n", argv[i]);
  66.         sprintf(methbuf, "x <120 1 '%s' 'r'>. <123 1>. <121 1>", argv [i]);
  67.         goDoIt (methbuf);
  68.     }
  69.  
  70.     /* when we are all done looking at the arguments, do initialization */
  71.     fprintf(stderr,"initialization\n");
  72.     /*debugging = true;*/
  73.     goDoIt("x nil initialize\n");
  74.     fprintf(stderr,"finished\n");
  75.  
  76.     /* exit and return - belt and suspenders, but it keeps lint happy */
  77.     exit(0); return 0;
  78. }
  79.  
  80. static void goDoIt(char *text)
  81. {     object process, stack, method;
  82.  
  83.     method = newMethod();
  84.     incr(method);
  85.     setInstanceVariables(nilobj);
  86.     ignore parse(method, text, false);
  87.  
  88.     process = allocObject(processSize);
  89.     incr(process);
  90.     stack = allocObject(50);
  91.     incr(stack);
  92.  
  93.     /* make a process */
  94.     basicAtPut(process, stackInProcess, stack);
  95.     basicAtPut(process, stackTopInProcess, newInteger(10));
  96.     basicAtPut(process, linkPtrInProcess, newInteger(2));
  97.  
  98.     /* put argument on stack */
  99.     basicAtPut(stack, 1, nilobj);    /* argument */
  100.     /* now make a linkage area in stack */
  101.     basicAtPut(stack, 2, nilobj);    /* previous link */
  102.     basicAtPut(stack, 3, nilobj);    /* context object (nil = stack) */
  103.     basicAtPut(stack, 4, newInteger(1));    /* return point */
  104.     basicAtPut(stack, 5, method);    /* method */
  105.     basicAtPut(stack, 6, newInteger(1));    /* byte offset */
  106.  
  107.     /* now go execute it */
  108.     while (execute(process, 15000)) fprintf(stderr,"..");
  109. }
  110.  
  111. /*
  112.     there is a sort of chicken and egg problem with regards to making
  113.     the initial image
  114. */
  115. static void makeInitialImage(void)
  116. {    object hashTable;
  117.     object symbolObj, symbolClass, classClass;
  118.  
  119.     /* first create the table, without class links */
  120.     symbols = allocObject(1);
  121.     incr(symbols);
  122.     hashTable = allocObject(3 * 53);
  123.     basicAtPut(symbols, 1, hashTable);
  124.  
  125.     /* next create #Symbol, Symbol and Class */
  126.     symbolObj = newSymbol("Symbol");
  127.     symbolClass = newClass("Symbol");
  128.     setClass(symbolObj, symbolClass);
  129.     classClass = newClass("Class");
  130.     setClass(symbolClass, classClass);
  131.     setClass(classClass, classClass);
  132.  
  133.     /* now fix up classes for symbol table */
  134.     /* and make a couple common classes, just to hold their places */
  135.     ignore newClass("Link");
  136.     ignore newClass("ByteArray");
  137.     setClass(hashTable, newClass("Array"));
  138.     setClass(symbols, newClass("Dictionary"));
  139.     setClass(nilobj, newClass("UndefinedObject"));
  140.     ignore newClass("String");
  141.     nameTableInsert(symbols, strHash("symbols"), newSymbol("symbols"), symbols);
  142.  
  143.     /* finally at least make true and false to be distinct */
  144.     trueobj = newSymbol("true");
  145.     nameTableInsert(symbols, strHash("true"), trueobj, trueobj);
  146.     falseobj = newSymbol("false");
  147.     nameTableInsert(symbols, strHash("false"), falseobj, falseobj);
  148. }
  149.  
  150.